package dao.impl;

import bean.OrderItem;
import dao.BaseDao;
import dao.OrderItemDao;

import java.util.List;

public class OrderItemImpl extends BaseDao<OrderItem> implements OrderItemDao {
    @Override
    public int saveOrderItem(OrderItem orderItem) {
        String sql = "insert into t_order_item(`order_code`,`name`,`count`,`unit_price`,`total_price`)" +
                " values(?,?,?,?,?)";

        return update(sql,orderItem.getOrderCode(),orderItem.getName(),orderItem.getCount(),orderItem.getUnitPrice(),
                orderItem.getTotalPrice());
    }

    @Override
    public List<OrderItem> queryOrderItemByOrderCode(Long orderCode) {
        try {
            String sql = "select `order_code` orderCode,`name`,`count`," +
                    "`unit_price` unitPrice,`total_price` totalPrice from t_order_item where `order_code`=?";
            return query(sql,orderCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
